import mongoose from 'mongoose'

const connectMongoDB = async () => {
    try {
        const conn = await mongoose.connect(process.env.MONGO_URI, {
            // NOTE: this fix: Error connection to mongodb: Authentication failed.
            authSource: 'admin',
        })
        console.log(`mongodb connected: ${conn.connection.host}:${conn.connection.port}`)
    } catch (error) {
        console.error(`Error connection to mongodb: ${error.message}`)
        process.exit(1)
    }
}

export default connectMongoDB
